package com.kurumi.aspect;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;
/*@Aspect
@Configuration*/
public class DeptAop {
	
	@Pointcut("execution(* com.kurumi.mapper.BaseInfoMapper.getMedicalDeptByHospitalCode(..))")  
    public void loginCell(){}

	@AfterReturning(pointcut="loginCell()",returning = "retVal")
	/*@AfterReturning(pointcut="@annotation(com.kurumi.mapper.BaseInfoMapper.getMedicalDeptByHospitalCode(.)))",returning="retVal")*/
	public void doFindByIdCheck(Object retVal) {
		try{
			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
			System.err.println(userName);
			List<Map<String,Object>> depts = (List<Map<String,Object>>) retVal;
			for (int index = depts.size()-1;index >=0;index--) {
				String code = (String)depts.get(index).get("uniq_code");
				if(!code.equalsIgnoreCase("3103")){
					depts.remove(index);
				}
			}
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		
		
	}
}
